Skip to content

Conversation

@rich7420
Copy link
Contributor

What changes were proposed in this pull request?

This PR unified the duplicated isValidKeyPath validation logic between OzoneFSUtils and OMClientRequest by extracting the common path validation into a shared private method validateKeyPathComponents, and made OMClientRequest.isValidKeyPath delegate to OzoneFSUtils.isValidKeyPath to remove code duplication.

What is the link to the Apache JIRA

HDDS-13444

How was this patch tested?

https://github.com/rich7420/ozone/actions/runs/20323872107

Copy link
Contributor

@echonesis echonesis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rich7420 , left some comments.

Comment on lines 132 to 135
if (allowLeadingSlash && i == 0) {
// Allow empty at start for absolute paths
continue;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this section is not included in original OMClientRequest.isValidKeyPath().
Please describe more details in the commit message section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure!

* Add reference counter to an object instance.
*/
class ReferenceCounted<T> {
public class ReferenceCounted<T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we keep it package-private?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I change to public cuz ci test error. I'll try to figure out the solution to keep it private.

* Whether the pathname is valid. Currently prohibits relative paths,
* names which contain a ":" or "//", or other non-canonical paths.
*/
public static boolean isValidName(String src) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use path instead of src to keep it consistent with isValidKeyPath

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, thanks for the reminder!

}

@Test
public void testIsValidKeyPath() throws OMException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add some tests like

  • assertEquals("a/b/", OzoneFSUtils.isValidKeyPath("a/b/", true));
  • assertThrows(OMException.class, () -> OzoneFSUtils.isValidKeyPath("/a/b", false));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no problem!

@adoroszlai adoroszlai added the code-cleanup Changes that aim to make code better, without changing functionality. label Dec 19, 2025
@adoroszlai adoroszlai requested a review from ivandika3 December 19, 2025 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-cleanup Changes that aim to make code better, without changing functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants